<?php

class ProductosController extends AppController {

    /**
     * This controller does not use a model
     *
     * @var array
     */
    public $uses = array('product');
    public $helpers = array('Html', 'Js', 'Fancybox.Fancybox');

    public function index() {
        $this->layout = 'avenida';
        
        $this->product->bindModel(array(
			'belongsTo' => array(
			'Images' => array(
			'foreignKey' => false,
			'conditions' => array('product.id = Images.product_id')
		))));
			
        $productos = $this->product->find('all', array(
			'conditions' => array(
				'product.is_active' => '1',
				'Images.is_front' => '1'
			)
		));
		
        //$this->filtrarImagenesFront($productos);                        
        $this->set('product', $productos);
    }
    
    
    
    
    
    private function filtrarImagenesFront(array &$productos){
        foreach($productos as $i=>$producto){
            foreach($producto["Images"] as $j=>$imagen){
                		var_dump($imagen); 
                if ($imagen["is_front"]) 
                    continue;
                unset($productos[$i]["Images"][$j]);
            }
        }          
    }

}
